<?
if(! defined('BASEPATH') ){ exit('Unable to view file.'); }

$site = $db->FetchArray($db->Query("SELECT * FROM `settings` LIMIT 1"));

if(isset($_POST['submit'])){
	$db->Query("UPDATE `settings` SET `site_name`='{$_POST['name']}', `site_description`='{$_POST['description']}', `site_url`='{$_POST['url']}', `paypal`='{$_POST['paypal']}', `site_email`='{$_POST['email']}', `maintenance`='{$_POST['mode']}', `m_progress`='{$_POST['progress']}'");
	$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Settings successfully changed</p></div>";
}
if(isset($_POST['usubmit'])){
	$db->Query("UPDATE `settings` SET `surf_time`='{$_POST['surf_time']}', `ref_coins`='{$_POST['ref_coins']}', `reg_coins`='{$_POST['reg_coins']}', `reg_status`='{$_POST['reg_status']}', `reg_logtype`='{$_POST['reg_logtype']}', `reg_reqmail`='{$_POST['reg_reqmail']}'");
	$mesaj = "<div class=\"message success\"><h3>Success!</h3><p>Settings successfully changed</p></div>";
}
?>
            <div id="page-subheader">
                <div class="wrapper clearfix">
                    <nav id="sub-nav"></nav>
                </div>
            </div>
<script> 
$(document).ready(function(){
    // Regular Expression to test whether the value is valid
    $.tools.validator.fn("[type=time]", "Please supply a valid time", function(input, value) { 
    	return /^\d\d:\d\d$/.test(value);
    });
     
    $.tools.validator.fn("[data-equals]", "Value not equal with the $1 field", function(input) {
    	var name = input.attr("data-equals"),
    		 field = this.getInputs().filter("[name=" + name + "]"); 
    	return input.val() == field.val() ? true : [name]; 
    });
     
    $.tools.validator.fn("[minlength]", function(input, value) {
    	var min = input.attr("minlength");
    	
    	return value.length >= min ? true : {     
    		en: "Please provide at least " +min+ " character" + (min > 1 ? "s" : "")
    	};
    });
     
    $.tools.validator.localizeFn("[type=time]", {
    	en: 'Please supply a valid time'
    });
     
    $("#form").validator({ 
    	position: 'left', 
    	offset: [25, 10],
    	messageClass:'form-error',
    	message: '<div><em/></div>' // em element is the arrow
    }).attr('novalidate', 'novalidate');

});
</script>
</header>
        
        <section id="content">
            <div class="wrapper">
                <section class="top"><? echo $mesaj;?>
                        <div class="grid_4 columns first">
                            <form id="form" method="post" class="form widget">
                                <header><h2>General Settings</h2></header>
                                <section>                 
                                    <fieldset>
                                         <dl>
                                             <dt></dt><dd><label>Site Title</label><input type="text" name="name" value="<?=(isset($_POST['name']) ? $_POST['name'] : $site['site_name'])?>" required="required" /></dd>
											 <dt></dt><dd><label>Site Description</label><input type="text" name="description" value="<?=(isset($_POST['description']) ? $_POST['description'] : $site['site_description'])?>" required="required" /></dd>
                                             <dt></dt><dd><label>Site URL</label><input type="text" name="url" value="<?=(isset($_POST['url']) ? $_POST['url'] : $site['site_url'])?>" required="required" /></dd>
											 <dt></dt><dd><label>Contact Email</label><input type="email" name="email" value="<?=(isset($_POST['email']) ? $_POST['email'] : $site['site_email'])?>" required="required" /></dd>
                                             <dt></dt><dd><label>Paypal Email</label><input type="email" name="paypal" value="<?=(isset($_POST['paypal']) ? $_POST['paypal'] : $site['paypal'])?>" required="required" /></dd>
											 <dt><label>Maintenance Mode</label></dt><dd></dd>
											 <dt></dt><dd><label>Status</label><select name="mode"><option value="0">Inactive</option><option value="1"<?=($site['maintenance'] != 0 ? ' selected' : '')?>>Active</option></select></dd>
											 <dt></dt><dd><label>Progress %</label><input type="text" name="progress" value="<?=$site['m_progress']?>" required="required" /></dd>
                                     	</dl>    
                                     </fieldset>
                                     <hr />
                                     <button class="button button-green" type="submit" name="submit">Submit</button>
                                     <button class="button button-gray" type="reset">Reset</button>
                                </section>
                            </form>
                        </div>

                    <div class="grid_4 columns">
                            <form id="form" method="post" class="form widget">
                                <header><h2>User Settings</h2></header>
                                <section>                 
                                    <fieldset>
                                         <dl>
                                             <dt></dt><dd><label>Coins per Referral</label><input type="text" name="ref_coins" value="<?=(isset($_POST['ref_coins']) ? $_POST['ref_coins'] : $site['ref_coins'])?>" required="required" /></dd>
											 <dt></dt><dd><label>Coins on Signup</label><input type="text" name="reg_coins" value="<?=(isset($_POST['reg_coins']) ? $_POST['reg_coins'] : $site['reg_coins'])?>" required="required" /></dd>
											 <dt></dt><dd><label>Auto-surf time (seconds)</label><input type="text" name="surf_time" value="<?=(isset($_POST['surf_time']) ? $_POST['surf_time'] : $site['surf_time'])?>" required="required" /></dd>
											 <dt></dt><dd><label>Login with</label><select name="reg_logtype"><option value="0">Username</option><option value="1"<?=($site['reg_logtype'] != 0 ? ' selected' : '')?>>Email</option></select></dd>
											 <dt></dt><dd><label>Email Confirmation</label><select name="reg_reqmail"><option value="0">Enabled</option><option value="1"<?=($site['reg_reqmail'] != 0 ? ' selected' : '')?>>Disabled</option></select></dd>
                                             <dt></dt><dd><label>Registration</label><select name="reg_status"><option value="0">Enabled</option><option value="1"<?=($site['reg_status'] != 0 ? ' selected' : '')?>>Disabled</option></select></dd>
                                     	</dl>    
                                     </fieldset>
                                     <hr />
                                     <button class="button button-green" type="submit" name="usubmit">Submit</button>
                                     <button class="button button-gray" type="reset">Reset</button>
                                </section>
                            </form>
                    </div>
                </section>
				<div class="clear"></div>
            </div>
            <div id="push"></div>
        </section>

    </div>
    
    <footer id="page-footer">
        <div id="footer-inner">
            <p class="wrapper">All rights reserved &copy; <a href="http://mafianet.org" target="_blank">MafiaNet</a> <?=date('Y')?></p>
        </div>
    </footer>
</body>
</html>